package org.ligson.hbase127;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.impl.DefaultPooledObject;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

public class HBasePoolFactory extends BasePooledObjectFactory<Connection> {
    private org.apache.hadoop.conf.Configuration config;

    public HBasePoolFactory(Configuration config) {
        this.config = config;
    }

    @Override
    public Connection create() throws Exception {
        return ConnectionFactory.createConnection(config);
    }

    @Override
    public PooledObject<Connection> wrap(Connection obj) {
        return new DefaultPooledObject<>(obj);
    }
}
